
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>路由信息对象 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="options.html" />
    
    
    <link rel="prev" href="router-view.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../installation.html">
            
                <a href="../installation.html">
            
                    
                    安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    基础
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../essentials/getting-started.html">
            
                <a href="../essentials/getting-started.html">
            
                    
                    开始
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../essentials/dynamic-matching.html">
            
                <a href="../essentials/dynamic-matching.html">
            
                    
                    动态路由匹配
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../essentials/nested-routes.html">
            
                <a href="../essentials/nested-routes.html">
            
                    
                    嵌套路由
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../essentials/navigation.html">
            
                <a href="../essentials/navigation.html">
            
                    
                    编程式导航
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../essentials/named-routes.html">
            
                <a href="../essentials/named-routes.html">
            
                    
                    命名路由
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../essentials/named-views.html">
            
                <a href="../essentials/named-views.html">
            
                    
                    命名视图
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="../essentials/redirect-and-alias.html">
            
                <a href="../essentials/redirect-and-alias.html">
            
                    
                    重定向 和 别名
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="../essentials/history-mode.html">
            
                <a href="../essentials/history-mode.html">
            
                    
                    HTML5 History 模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    进阶
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../advanced/navigation-guards.html">
            
                <a href="../advanced/navigation-guards.html">
            
                    
                    导航钩子
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../advanced/meta.html">
            
                <a href="../advanced/meta.html">
            
                    
                    路由元信息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../advanced/transitions.html">
            
                <a href="../advanced/transitions.html">
            
                    
                    过渡动效
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../advanced/data-fetching.html">
            
                <a href="../advanced/data-fetching.html">
            
                    
                    数据获取
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../advanced/scroll-behavior.html">
            
                <a href="../advanced/scroll-behavior.html">
            
                    
                    滚动行为
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../advanced/lazy-loading.html">
            
                <a href="../advanced/lazy-loading.html">
            
                    
                    懒加载
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    API 文档
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="router-link.html">
            
                <a href="router-link.html">
            
                    
                    router-link
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="router-view.html">
            
                <a href="router-view.html">
            
                    
                    router-view
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.5.3" data-path="route-object.html">
            
                <a href="route-object.html">
            
                    
                    路由信息对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="options.html">
            
                <a href="options.html">
            
                    
                    Router 构造配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="router-instance.html">
            
                <a href="router-instance.html">
            
                    
                    Router 实例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="component-injections.html">
            
                <a href="component-injections.html">
            
                    
                    对组件注入
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >路由信息对象</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x8DEF;&#x7531;&#x4FE1;&#x606F;&#x5BF9;&#x8C61;">&#x8DEF;&#x7531;&#x4FE1;&#x606F;&#x5BF9;&#x8C61;</h1>
<p>&#x4E00;&#x4E2A; <strong>route object&#xFF08;&#x8DEF;&#x7531;&#x4FE1;&#x606F;&#x5BF9;&#x8C61;&#xFF09;</strong> &#x8868;&#x793A;&#x5F53;&#x524D;&#x6FC0;&#x6D3B;&#x7684;&#x8DEF;&#x7531;&#x7684;&#x72B6;&#x6001;&#x4FE1;&#x606F;&#xFF0C;&#x5305;&#x542B;&#x4E86;&#x5F53;&#x524D; URL &#x89E3;&#x6790;&#x5F97;&#x5230;&#x7684;&#x4FE1;&#x606F;&#xFF0C;&#x8FD8;&#x6709; URL &#x5339;&#x914D;&#x5230;&#x7684; <strong>route records&#xFF08;&#x8DEF;&#x7531;&#x8BB0;&#x5F55;&#xFF09;</strong>&#x3002;</p>
<p>route object &#x662F; immutable&#xFF08;&#x4E0D;&#x53EF;&#x53D8;&#xFF09; &#x7684;&#xFF0C;&#x6BCF;&#x6B21;&#x6210;&#x529F;&#x7684;&#x5BFC;&#x822A;&#x540E;&#x90FD;&#x4F1A;&#x4EA7;&#x751F;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x5BF9;&#x8C61;&#x3002;</p>
<p>route object &#x51FA;&#x73B0;&#x5728;&#x591A;&#x4E2A;&#x5730;&#x65B9;:</p>
<ul>
<li><p>&#x7EC4;&#x4EF6;&#x5185;&#x7684; <code>this.$route</code> &#x548C; <code>$route</code> watcher &#x56DE;&#x8C03;&#xFF08;&#x76D1;&#x6D4B;&#x53D8;&#x5316;&#x5904;&#x7406;&#xFF09;;</p>
</li>
<li><p><code>router.match(location)</code> &#x7684;&#x8FD4;&#x56DE;&#x503C;</p>
</li>
<li><p>&#x5BFC;&#x822A;&#x94A9;&#x5B50;&#x7684;&#x53C2;&#x6570;&#xFF1A;</p>
<pre><code class="lang-js">router.beforeEach((to, <span class="hljs-keyword">from</span>, next) =&gt; {
  <span class="hljs-comment">// to &#x548C; from &#x90FD;&#x662F; &#x8DEF;&#x7531;&#x4FE1;&#x606F;&#x5BF9;&#x8C61;</span>
})
</code></pre>
</li>
<li><p><code>scrollBehavior</code> &#x65B9;&#x6CD5;&#x7684;&#x53C2;&#x6570;:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> router = <span class="hljs-keyword">new</span> VueRouter({
  scrollBehavior (to, <span class="hljs-keyword">from</span>, savedPosition) {
    <span class="hljs-comment">// to &#x548C; from &#x90FD;&#x662F; &#x8DEF;&#x7531;&#x4FE1;&#x606F;&#x5BF9;&#x8C61;</span>
  }
})
</code></pre>
</li>
</ul>
<h3 id="&#x8DEF;&#x7531;&#x4FE1;&#x606F;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;">&#x8DEF;&#x7531;&#x4FE1;&#x606F;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;</h3>
<ul>
<li><p><strong>$route.path</strong></p>
<ul>
<li><p>&#x7C7B;&#x578B;: <code>string</code></p>
<p>&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5BF9;&#x5E94;&#x5F53;&#x524D;&#x8DEF;&#x7531;&#x7684;&#x8DEF;&#x5F84;&#xFF0C;&#x603B;&#x662F;&#x89E3;&#x6790;&#x4E3A;&#x7EDD;&#x5BF9;&#x8DEF;&#x5F84;&#xFF0C;&#x5982; <code>&quot;/foo/bar&quot;</code>&#x3002;</p>
</li>
</ul>
</li>
<li><p><strong>$route.params</strong></p>
<ul>
<li>&#x7C7B;&#x578B;: <code>Object</code></li>
</ul>
<p>&#x4E00;&#x4E2A; key/value &#x5BF9;&#x8C61;&#xFF0C;&#x5305;&#x542B;&#x4E86; &#x52A8;&#x6001;&#x7247;&#x6BB5; &#x548C; &#x5168;&#x5339;&#x914D;&#x7247;&#x6BB5;&#xFF0C;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x8DEF;&#x7531;&#x53C2;&#x6570;&#xFF0C;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x7A7A;&#x5BF9;&#x8C61;&#x3002;</p>
</li>
<li><p><strong>$route.query</strong></p>
<ul>
<li><p>&#x7C7B;&#x578B;: <code>Object</code></p>
<p>&#x4E00;&#x4E2A; key/value &#x5BF9;&#x8C61;&#xFF0C;&#x8868;&#x793A; URL &#x67E5;&#x8BE2;&#x53C2;&#x6570;&#x3002;&#x4F8B;&#x5982;&#xFF0C;&#x5BF9;&#x4E8E;&#x8DEF;&#x5F84; <code>/foo?user=1</code>&#xFF0C;&#x5219;&#x6709; <code>$route.query.user == 1</code>&#xFF0C;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x67E5;&#x8BE2;&#x53C2;&#x6570;&#xFF0C;&#x5219;&#x662F;&#x4E2A;&#x7A7A;&#x5BF9;&#x8C61;&#x3002;</p>
</li>
</ul>
</li>
<li><p><strong>$route.hash</strong></p>
<ul>
<li><p>&#x7C7B;&#x578B;: <code>string</code></p>
<p>&#x5F53;&#x524D;&#x8DEF;&#x7531;&#x7684; hash &#x503C; (&#x5E26; <code>#</code>) &#xFF0C;&#x5982;&#x679C;&#x6CA1;&#x6709; hash &#x503C;&#xFF0C;&#x5219;&#x4E3A;&#x7A7A;&#x5B57;&#x7B26;&#x4E32;&#x3002;</p>
</li>
</ul>
</li>
</ul>
<ul>
<li><p><strong>$route.fullPath</strong></p>
<ul>
<li><p>&#x7C7B;&#x578B;: <code>string</code></p>
<p>&#x5B8C;&#x6210;&#x89E3;&#x6790;&#x540E;&#x7684; URL&#xFF0C;&#x5305;&#x542B;&#x67E5;&#x8BE2;&#x53C2;&#x6570;&#x548C; hash &#x7684;&#x5B8C;&#x6574;&#x8DEF;&#x5F84;&#x3002;</p>
</li>
</ul>
</li>
<li><p><strong>$route.matched</strong></p>
<ul>
<li>&#x7C7B;&#x578B;: <code>Array&lt;RouteRecord&gt;</code></li>
</ul>
<p>&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#xFF0C;&#x5305;&#x542B;&#x5F53;&#x524D;&#x8DEF;&#x7531;&#x7684;&#x6240;&#x6709;&#x5D4C;&#x5957;&#x8DEF;&#x5F84;&#x7247;&#x6BB5;&#x7684; <strong>&#x8DEF;&#x7531;&#x8BB0;&#x5F55;</strong> &#x3002;&#x8DEF;&#x7531;&#x8BB0;&#x5F55;&#x5C31;&#x662F; <code>routes</code> &#x914D;&#x7F6E;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x5BF9;&#x8C61;&#x526F;&#x672C;&#xFF08;&#x8FD8;&#x6709;&#x5728; <code>children</code> &#x6570;&#x7EC4;&#xFF09;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> router = <span class="hljs-keyword">new</span> VueRouter({
  routes: [
    <span class="hljs-comment">// &#x4E0B;&#x9762;&#x7684;&#x5BF9;&#x8C61;&#x5C31;&#x662F; route record</span>
    { path: <span class="hljs-string">&apos;/foo&apos;</span>, component: Foo,
      children: [
        <span class="hljs-comment">// &#x8FD9;&#x4E5F;&#x662F;&#x4E2A; route record</span>
        { path: <span class="hljs-string">&apos;bar&apos;</span>, component: Bar }
      ]
    }
  ]
})
</code></pre>
<p>&#x5F53; URL &#x4E3A; <code>/foo/bar</code>&#xFF0C;<code>$route.matched</code> &#x5C06;&#x4F1A;&#x662F;&#x4E00;&#x4E2A;&#x5305;&#x542B;&#x4ECE;&#x4E0A;&#x5230;&#x4E0B;&#x7684;&#x6240;&#x6709;&#x5BF9;&#x8C61;&#xFF08;&#x526F;&#x672C;&#xFF09;&#x3002;</p>
</li>
<li><p><strong>$route.name</strong></p>
<p>&#x5F53;&#x524D;&#x8DEF;&#x7531;&#x7684;&#x540D;&#x79F0;&#xFF0C;&#x5982;&#x679C;&#x6709;&#x7684;&#x8BDD;&#x3002;&#xFF08;&#x67E5;&#x770B; <a href="../essentials/named-routes.html">&#x547D;&#x540D;&#x8DEF;&#x7531;</a>&#xFF09;</p>
</li>
</ul>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="router-view.html" class="navigation navigation-prev " aria-label="Previous page: router-view">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="options.html" class="navigation navigation-next " aria-label="Next page: Router 构造配置">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"路由信息对象","level":"1.5.3","depth":2,"next":{"title":"Router 构造配置","level":"1.5.4","depth":2,"path":"api/options.md","ref":"api/options.md","articles":[]},"previous":{"title":"router-view","level":"1.5.2","depth":2,"path":"api/router-view.md","ref":"api/router-view.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"api/route-object.md","mtime":"2017-03-04T12:16:27.890Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-03-06T16:00:44.406Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

